# -*- coding: utf-8 -*-
import time
from application import app

# 统一封装链接管理器
class UrlManager(object):
    def __init__(self):
        pass

    @staticmethod
    def buildUrl(path):
        return path

    # 设置时间为版本号的目的 因为浏览器只要一直收到变化的量就不会用缓存 这样可以保证不需要老是清缓存
    @staticmethod
    def buildStaticUrl(path):
        release_version = app.config.get('RELEASE_VERSION')
        # 动态版本号
        ver = "%s" % (int(time.time())) if not release_version else release_version
        path = "/static" + path + "?ver=" + ver
        return UrlManager.buildUrl(path)

    # 拼接图片的url
    # 因为是给前端访问 必须是完整的url  域名+图片前缀+key
    @staticmethod
    def buildImageUrl(path):
        app_config = app.config['APP']
        url = app_config['domain'] + app.config['UPLOAD']['prefix_url'] + path
        return url

# a = UrlManager.buildStaticUrl('123')
